package cn.kent.controller;

import cn.kent.config.RabbitConfig;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageBuilder;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
public class HelloController {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @RequestMapping("hello")
    public void hello() {
        Message msg = MessageBuilder.withBody(("hello, 鹏鹏!" + new Date()).getBytes()).build();
        rabbitTemplate.send(RabbitConfig.EXCHANGE_NAME, RabbitConfig.QUEUE_NAME, msg);
    }
}
